<%--
  Created by IntelliJ IDEA.
  User: cos
  Date: 2022/2/28
  Time: 14:12
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
</head>
<body>
<form action="/emp?type=reg" method="post">
    用户名: <input type="text" name="ename"> <br>
    性别: <input type="radio" name="esex" value="男" checked>男
    <input type="radio" name="esex" value="女">女 <br>
    工资: <input type="number" name="salary"> <br>
    密码: <input type="password" name="pwd"> <br>
    部门编号: <input type="number" name="dno"> <br>
    手机号: <input type="text" name="phone"> <button type="button" id="send">点击发送短信</button><br>
    短信验证码: <input type="text" id="phoneMessage"> <br>
    <input type="submit" disabled id="subBtn">
    <span>${msg}</span>
</form>
<script>
    $(function () {
        $("#send").click(function () {
            //请求过去短信发送
            let phone = $(this).prev().val();
            console.log(phone);//打印到控制台 (前端的控制台)
            $.ajax({
                type:"get",
                url:"/emp?type=sendMessage&phone="+phone,
                success:function (data) {
                    alert(data);
                }
            })
        })
        $("#phoneMessage").change(function () {
            $.ajax({
                type:"get",
                url:"/emp?type=checkMsg&msg="+$(this).val(),
                success:function (data) {
                    alert(data);
                    //1 成功 0 失败
                    if (data==1) {
                        alert("验证码正确");
                        $("#subBtn").prop("disabled",false);
                    }else{
                        alert("验证码失败");
                        $("#subBtn").prop("disabled",true);
                    }
                }
            })
        })


    })

</script>


</body>
</html>
